package LeetcodeTest_twenty_six;

import java.util.Scanner;
public class isSameTree
{
    public static void main(String[] args)
    {
        TreeNode root1=new TreeNode();
        TreeNode root2=new TreeNode();
        root1=Solution.createTree(root1);
        root2=Solution.createTree(root2);
        System.out.println(Solution.isSameTree(root1,root2));
    }
}
class Solution
{
    public static boolean flag=true;
    public static boolean isSameTree(TreeNode p, TreeNode q)
    {
        boolean answer;
        difs(p,q);
        answer=flag;
        flag=true;
        return answer;
    }
    public static void difs(TreeNode p, TreeNode q)
    {
        if(p!=null && q!=null)
        {
            if(p.val==q.val)
            {
                difs(p.left,q.left);
                difs(p.right,q.right);
            }
            else
                flag=false;
        }
        if((p==null&& q!=null)||(p!=null && q==null))
            flag=false;
    }
    public static TreeNode createTree(TreeNode T)
    {
        Scanner reader=new Scanner(System.in);
        int a=reader.nextInt();
        TreeNode p=null;
        if (a==-1)
            p=null;
        else
            p = new TreeNode(a);
        T=p;
        if(T==null)
            return T;
        else
        {
            T.left = createTree(T.left);
            T.right = createTree(T.right);
        }
        return T;
    }
}
class TreeNode
{
    int val;
    TreeNode left;
    TreeNode right;
    TreeNode() {}
    TreeNode(int val) { this.val = val; }
    TreeNode(int val, TreeNode left, TreeNode right)
    {
        this.val = val;
        this.left = left;
        this.right = right;
    }
}